
<form action="" method="post" enctype="multipart/form-data">
	<table style="width:650px;">
    	<tr><td>Tiêu đề:</td></tr>
			<tr>
				<td><input type="text" name="txtTieude"/></td>
			</tr>
			<tr>
				<td>Nội dung:</td>
			</tr>
			<tr>
				<td><textarea rows="40" cols="70" class="ckeditor" id="editor1" name="txtNoidung"></textarea></td>
			</tr>
			<tr>
				<td>Đính kèm:</td>
			</tr>
			<tr>
				<td>
					<input type="file" name="myfile"/>
				</td>
			</tr>
			<tr>
				<td>
					<input type="submit"  name="btnUpload" value="Đăng tin"/>
					<input type="reset" name="btnReset" value="Reset"/>
				</td>
			</tr>
	</table>
</form>
<?php
        $dt = new DateTime('now', new DateTimeZone('Asia/Ho_Chi_Minh'));
        $currentTime=$dt->format('Y-m-d H:i:s'); // get current date
        $file=$_FILES["myfile"]; 
        $size=$file["size"];
        $tempdir=$file["tmp_name"];
        $tieude=$_POST["txtTieude"];
        $noidung=$_POST["txtNoidung"];
        $hoten=$_SESSION["hoten"];
        $uploadOk = 0;
        if($_POST['btnUpload'])
        {
            if($file!=''){
                if($size < 1000000)
                {
                    $filename=time()."_".$file["name"];
                    $target_dir="data/".$filename;
                    if(move_uploaded_file($tempdir,$target_dir))
                        $uploadOk = 1;
                }
                else
                {
                    echo "<script>alert('tải quá 10MB')</script>";
                }
            }
            $sql="INSERT INTO `thongbao` VALUES ('','$tieude','$noidung','$target_dir','$hoten','$currentTime')";
            $rs=mysql_query($sql);
            if($rs){
               echo '<script>
                	   alert("Upload thanh cong");
                	</script>';
            }else{
               echo '<script>
      		      	  alert("Upload that bai");
                	</script>'; 
            } 
        }
?>
